package com.yonyou.pmclouds.messagenotice.constructor.config;

import com.yonyou.pmclouds.messagenotice.constructor.impl.MessageNoticeConstructor;
import com.yonyou.pmclouds.messagenotice.constructor.itf.IMessageNoticeConstructor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MessageNoticeConfiguration implements BeanPostProcessor{

    private MessageNoticeConstructor constructor = new MessageNoticeConstructor();

    @Bean
    public MessageNoticeConstructor messageNoticeConstructor() {
        return constructor;
    }


    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof IMessageNoticeConstructor) {
            constructor.addConstructor((IMessageNoticeConstructor) bean);
        }
        return bean;
    }
}
